home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DJGPP / DJ111M2.ZIP / docs / djgpp / libc-d-f.tex < prev    next >
Text File  |  1994-01-08  |  40KB  |  1,827 lines

  1. @c ----------------------------------------------------------------------
  2. @node delay, difftime, _ctype_, Alphabetical List
  3.  
  4. @heading @code{delay}
  5. @subheading Syntax
  6.  
  7. @example
  8. void delay(unsigned msec);
  9. @end example
  10.  
  11. @subheading Description
  12.  
  13. This function causes the program to pause for @var{msec} milliseconds. 
  14. It uses the @code{int 15h} delay function to relinquish the CPU to other
  15. programs that might need it. 
  16.  
  17. @subheading Return Value
  18.  
  19. None.
  20.  
  21. @subheading Example
  22.  
  23. @example
  24. delay(200); /* delay for 1/5 second */
  25. @end example
  26.  
  27. @c ----------------------------------------------------------------------
  28. @node difftime, disable, delay, Alphabetical List
  29.  
  30. @heading @code{difftime}
  31. @subheading Syntax
  32.  
  33. @example
  34. #include <time.h>
  35.  
  36. double difftime(time_t t1, time_t t0);
  37. @end example
  38.  
  39. @subheading Description
  40.  
  41. This function returns the difference in time, in seconds, from @var{t0}
  42. to @var{t1}. 
  43.  
  44. @subheading Return Value
  45.  
  46. The number of seconds.
  47.  
  48. @subheading Example
  49.  
  50. @example
  51. time_t t1, t0;
  52. double elapsed;
  53. time(&t0);
  54. do_something();
  55. time(&t1);
  56. elapsed = difftime(t1, t0);
  57. @end example
  58.  
  59. @c ----------------------------------------------------------------------
  60. @node disable, div, difftime, Alphabetical List
  61.  
  62. @heading @code{disable}
  63. @subheading Syntax
  64.  
  65. @example
  66. #include <dos.h>
  67.  
  68. void disable(void);
  69. @end example
  70.  
  71. @subheading Description
  72.  
  73. This function disables interrupts.
  74.  
  75. @xref{enable}
  76.  
  77. @subheading Return Value
  78.  
  79. None.
  80.  
  81. @subheading Example
  82.  
  83. @example
  84. disable();
  85. ...
  86. enable();
  87. @end example
  88.  
  89. @c ----------------------------------------------------------------------
  90. @node div, _doprnt, disable, Alphabetical List
  91.  
  92. @heading @code{div}
  93. @subheading Syntax
  94.  
  95. @example
  96. #include <stdlib.h>
  97.  
  98. div_t div(int numberator, int denomonator);
  99. @end example
  100.  
  101. @subheading Description
  102.  
  103. Returns the quotient and remainder of the division @var{numberator}
  104. divided by @var{denomonator}.  The return type is as follows:
  105.  
  106. @example
  107. typedef struct @{
  108.   int quot;
  109.   int rem;
  110. @} div_t;
  111. @end example
  112.  
  113. @subheading Return Value
  114.  
  115. The results of the division are returned.
  116.  
  117. @subheading Example
  118.  
  119. @example
  120. div_t d = div(42, 3);
  121. printf("42 = %d x 3 + %d\n", d.quot, d.rem);
  122. @end example
  123.  
  124. @c ----------------------------------------------------------------------
  125. @node _doprnt, _doscan, div, Alphabetical List
  126.  
  127. @heading @code{_doprnt}
  128. @subheading Syntax
  129.  
  130. @example
  131. #include <stdio.h>
  132.  
  133. int _doprnt(const char *format, void *params, FILE *file);
  134. @end example
  135.  
  136. @subheading Description
  137.  
  138. This is an internal function that is used by all the @code{printf} style
  139. functions, which simply pass their format, arguments, and stream to this
  140. function. 
  141.  
  142. @xref{printf} for a discussion of the allowed formats and arguments. 
  143.  
  144. @subheading Return Value
  145.  
  146. The number of characters generated is returned.
  147.  
  148. @subheading Example
  149.  
  150. @example
  151. int args[] = @{ 1, 2, 3, 66 @};
  152. _doprnt("%d %d %d %c\n", args, stdout);
  153. @end example
  154.  
  155. @c ----------------------------------------------------------------------
  156. @node _doscan, _doscan_low, _doprnt, Alphabetical List
  157.  
  158. @heading @code{_doscan}
  159. @subheading Syntax
  160.  
  161. @example
  162. #include <stdio.h>
  163.  
  164. int _doscan(FILE *file, const char *format, void **ptrs_to_args);
  165. @end example
  166.  
  167. @subheading Description
  168.  
  169. This is an internal function that is used by all the @code{scanf} style
  170. functions, which simply pass their format, arguments, and stream to this
  171. function. 
  172.  
  173. @xref{scanf} for a discussion of the allowed formats and arguments. 
  174.  
  175. @subheading Return Value
  176.  
  177. The number of characters successfully scanned is returned, or -1 on
  178. error. 
  179.  
  180. @subheading Example
  181.  
  182. @example
  183. int x, y;
  184. int *args[2];
  185. args[0] = &x;
  186. args[1] = &y;
  187. _doscan(stdin, "%d %d", args);
  188. @end example
  189.  
  190. @c ----------------------------------------------------------------------
  191. @node _doscan_low, dosmemget, _doscan, Alphabetical List
  192.  
  193. @heading @code{_doscan_low}
  194.  
  195. @subheading Description
  196.  
  197. This is an internal function used by _doscan.
  198.  
  199. @c ----------------------------------------------------------------------
  200. @node dosmemget, dosmemput, _doscan_low, Alphabetical List
  201.  
  202. @heading @code{dosmemget}
  203. @subheading Syntax
  204.  
  205. @example
  206. #include <go32.h>
  207.  
  208. void dosmemget(int offset, int length, void *buffer);
  209. @end example
  210.  
  211. @subheading Description
  212.  
  213. This function transfers data from MS-DOS's conventional memory space to
  214. the program's virtual address space.  The @var{offset} is a physical
  215. address, which can be computed from a real-mode segment/offset pair as
  216. follows:
  217.  
  218. @example
  219. offset = segment * 16 + offset;
  220. @end example
  221.  
  222. The @var{length} is the number of bytes to transfer, and @var{buffer} is
  223. a pointer to somewhere in your virtual address space (such as memory
  224. obtained from @code{malloc}) where the data will go.
  225.  
  226. @subheading Return Value
  227.  
  228. None.
  229.  
  230. @subheading Example
  231.  
  232. @example
  233. unsigned short shift_state;
  234. dosmemget(0x417, 2, &shift_state);
  235. if (shift_state & 0x0004)
  236.   /* Ctrl key pressed */;
  237. @end example
  238.  
  239. @c ----------------------------------------------------------------------
  240. @node dosmemput, dup, dosmemget, Alphabetical List
  241.  
  242. @heading @code{dosmemput}
  243. @subheading Syntax
  244.  
  245. @example
  246. #include <go32.h>
  247.  
  248. void dosmemput(const void *buffer, int length, int offset);
  249. @end example
  250.  
  251. @subheading Description
  252.  
  253. This function transfers data from the program's virtual address space to
  254. MS-DOS's conventional memory space.  The @var{offset} is a physical
  255. address, which can be computed from a real-mode segment/offset pair as
  256. follows:
  257.  
  258. @example
  259. offset = segment * 16 + offset;
  260. @end example
  261.  
  262. The @var{length} is the number of bytes to transfer, and @var{buffer} is
  263. a pointer to somewhere in your virtual address space (such as memory
  264. obtained from @code{malloc}) where the data will come from. 
  265.  
  266. @subheading Return Value
  267.  
  268. None.
  269.  
  270. @subheading Example
  271.  
  272. @example
  273. unsigned short save_screen[25][80];
  274. dosmemput(save_screen, 0xb8000, 80*2*25);
  275. @end example
  276.  
  277. @c ----------------------------------------------------------------------
  278. @node dup, dup2, dosmemput, Alphabetical List
  279.  
  280. @heading @code{dup}
  281. @subheading Syntax
  282.  
  283. @example
  284. #include <osfcn.h>
  285.  
  286. int dup(int old_handle);
  287. @end example
  288.  
  289. @subheading Description
  290.  
  291. This function duplicates the given file handle.  Both handles refer to
  292. the same file and file pointer. 
  293.  
  294. @subheading Return Value
  295.  
  296. The new file handle, or -1 if error.
  297.  
  298. @subheading Example
  299.  
  300. @example
  301. do_file(dup(fileno(stdin)));
  302. @end example
  303.  
  304. @c ----------------------------------------------------------------------
  305. @node dup2, enable, dup, Alphabetical List
  306.  
  307. @heading @code{dup2}
  308. @subheading Syntax
  309.  
  310. @example
  311. #include <osfcn.h>
  312.  
  313. int dup2(int existing_handle, int new_handle);
  314. @end example
  315.  
  316. @subheading Description
  317.  
  318. This call causes @var{new_handle} to refer to the same file and file
  319. pointer as @var{existing_handle}.  If @var{new_handle} is an open file,
  320. it is closed. 
  321.  
  322. @subheading Return Value
  323.  
  324. The new handle, or -1 on error.
  325.  
  326. @subheading Example
  327.  
  328. @example
  329. /* copy new file to stdin stream */
  330. close(0);
  331. dup2(new_stdin, 0);
  332. close(new_stdin);
  333. @end example
  334.  
  335. @c ----------------------------------------------------------------------
  336. @node enable, endgrent, dup2, Alphabetical List
  337.  
  338. @heading @code{enable}
  339. @subheading Syntax
  340.  
  341. @example
  342. #include <dos.h>
  343.  
  344. void enable(void);
  345. @end example
  346.  
  347. @subheading Description
  348.  
  349. This function enables interrupts.
  350.  
  351. @xref{disable}
  352.  
  353. @subheading Return Value
  354.  
  355. None.
  356.  
  357. @subheading Example
  358.  
  359. @example
  360. disable();
  361. ...
  362. enable();
  363. @end example
  364.  
  365. @c ----------------------------------------------------------------------
  366. @node endgrent, endmntent, enable, Alphabetical List
  367.  
  368. @heading @code{endgrent}
  369. @subheading Syntax
  370.  
  371. @example
  372. #include <grp.h>
  373.  
  374. void endgrent(void);
  375. @end example
  376.  
  377. @subheading Description
  378.  
  379. This function should be called after all calls to getgrent, getgrgid, or
  380. getgrnam. 
  381.  
  382. @subheading Return Value
  383.  
  384. None.
  385.  
  386. @subheading Example
  387.  
  388. @xref{getgrent}
  389.  
  390. @c ----------------------------------------------------------------------
  391. @node endmntent, endpwent, endgrent, Alphabetical List
  392.  
  393. @heading @code{endmntent}
  394. @subheading Syntax
  395.  
  396. @example
  397. #include <mntent.h>
  398.  
  399. int endmntent(FILE *filep);
  400. @end example
  401.  
  402. @subheading Description
  403.  
  404. This function should be called after the last call to getmntent (@xref{getmntent}).
  405.  
  406. @subheading Return Value
  407.  
  408. This function always returns one.
  409.  
  410. @c ----------------------------------------------------------------------
  411. @node endpwent, errno, endmntent, Alphabetical List
  412.  
  413. @heading @code{endpwent}
  414. @subheading Syntax
  415.  
  416. @example
  417. #include <pwd.h>
  418.  
  419. void endpwent(void);
  420. @end example
  421.  
  422. @subheading Description
  423.  
  424. This function should be called after the last call to getpwent (@xref{getpwent}).
  425.  
  426. @subheading Return Value
  427.  
  428. None.
  429.  
  430. @c ----------------------------------------------------------------------
  431. @node errno, exec*, endpwent, Alphabetical List
  432.  
  433. @heading @code{errno}
  434. @subheading Syntax
  435.  
  436. @example
  437. #include <errno.h>
  438.  
  439. extern int errno;
  440. @end example
  441.  
  442. @subheading Description
  443.  
  444. This variable is used to hold the value of the error of the last
  445. function call.  For details about the various error types, please refer
  446. to the file @file{include/errno.h}. 
  447.  
  448. @xref{perror}
  449.  
  450. @c ----------------------------------------------------------------------
  451. @node exec*, _exit, errno, Alphabetical List
  452.  
  453. @heading @code{exec*}
  454. @subheading Syntax
  455.  
  456. @example
  457. #include <process.h>
  458.  
  459. int execl(const char *path, const char *argv0, ...);
  460. int execle(const char *path, const char *argv0, ... /*, const char **envp */);
  461. int execlp(const char *path, const char *argv0, ...);
  462. int execlpe(const char *path, const char *argv0, ... /*, const char **envp */);
  463.  
  464. int execv(const char *path, const char **argv);
  465. int execve(const char *path, const char **argv, const char **envp);
  466. int execvp(const char *path, const char **argv);
  467. int execvpe(const char *path, const char **argv, const char **envp);
  468. @end example
  469.  
  470. @subheading Description
  471.  
  472. These functions operate by calling @code{spawn*} with a type of
  473. @code{P_OVERLAY}.  Refer to @xref{spawn*} for a full description. 
  474.  
  475. @subheading Return Value
  476.  
  477. If successful, these functions do not return.  If there is an error,
  478. these functions return -1 and set @code{errno} to indicate the error. 
  479.  
  480. @subheading Example
  481.  
  482. @example
  483. execlp("gcc", "gcc", "-v", "hello.c", 0);
  484. @end example
  485.  
  486. @c ----------------------------------------------------------------------
  487. @node _exit, exit, exec*, Alphabetical List
  488.  
  489. @heading @code{_exit}
  490. @subheading Syntax
  491.  
  492. @example
  493. #include <stdlib.h>
  494.  
  495. void volatile _exit(int exit_code);
  496. @end example
  497.  
  498. @subheading Description
  499.  
  500. This function exits the application immediately, without performing any
  501. @code{atexit} or @code{on_exit} requests or closing any files.  The
  502. program will return @var{exit_code} to the calling process as the exit
  503. code. 
  504.  
  505. @subheading Return Value
  506.  
  507. This function does not return.
  508.  
  509. @c ----------------------------------------------------------------------
  510. @node exit, _f_morefiles, _exit, Alphabetical List
  511.  
  512. @heading @code{exit}
  513. @subheading Syntax
  514.  
  515. @example
  516. #include <stdlib.h>
  517.  
  518. void volatile exit(int exit_code);
  519. @end example
  520.  
  521. @subheading Description
  522.  
  523. This function exits the program, returning @var{exit_code} to the
  524. calling process.  Before exiting, all open files are closed and all
  525. @code{atexit} and @code{on_exit} requests are processed. 
  526.  
  527. @subheading Return Value
  528.  
  529. This function does not return.
  530.  
  531. @subheading Example
  532.  
  533. @example
  534. if (argc < 4)
  535. @{
  536.   print_usage();
  537.   exit(1);
  538. @}
  539. @end example
  540.  
  541. @c ----------------------------------------------------------------------
  542. @node _f_morefiles, fchmod, exit, Alphabetical List
  543.  
  544. @heading @code{_f_morefiles}
  545.  
  546. @subheading Description
  547.  
  548. This is an internal function used by @code{fopen}. @xref{fopen}
  549.  
  550. @c ----------------------------------------------------------------------
  551. @node fchmod, fclose, _f_morefiles, Alphabetical List
  552.  
  553. @heading @code{fchmod}
  554. @subheading Syntax
  555.  
  556. @example
  557. #include <unistd.h>
  558.  
  559. int fchmod(int file, int mode);
  560. @end example
  561.  
  562. @subheading Description
  563.  
  564. This function is not implemented under MS-DOS.  If you call it, it will
  565. only write a warning to stderr. 
  566.  
  567. @c ----------------------------------------------------------------------
  568. @node fclose, fdopen, fchmod, Alphabetical List
  569.  
  570. @heading @code{fclose}
  571. @subheading Syntax
  572.  
  573. @example
  574. #include <stdio.h>
  575.  
  576. int fclose(FILE *file);
  577. @end example
  578.  
  579. @subheading Description
  580.  
  581. This function closes the given @var{file}.
  582.  
  583. @subheading Return Value
  584.  
  585. Zero on success, else @code{EOF}. 
  586.  
  587. @subheading Example
  588.  
  589. @example
  590. FILE *f = fopen("data", "r");
  591. fprintf(f, "Hello\n");
  592. fclose(f);
  593. @end example
  594.  
  595. @c ----------------------------------------------------------------------
  596. @node fdopen, feof, fclose, Alphabetical List
  597.  
  598. @heading @code{fdopen}
  599. @subheading Syntax
  600.  
  601. @example
  602. #include <stdio.h>
  603.  
  604. FILE *fdopen(int fd, const char *mode);
  605. @end example
  606.  
  607. @subheading Description
  608.  
  609. This function opens a stream-type file that uses the given @var{fd}
  610. file, which must already be open.  The file is opened with the modes
  611. specified by @var{mode}, which is the same as for @code{fopen}. 
  612. @xref{fopen}
  613.  
  614. @subheading Return Value
  615.  
  616. The newly created @code{FILE *}, or @code{NULL} on error.
  617.  
  618. @subheading Example
  619.  
  620. @example
  621. FILE *stdprn = fdopen(4, "w");
  622. @end example
  623.  
  624. @c ----------------------------------------------------------------------
  625. @node feof, ferror, fdopen, Alphabetical List
  626.  
  627. @heading @code{feof}
  628. @subheading Syntax
  629.  
  630. @example
  631. #include <stdio.h>
  632.  
  633. int feof(FILE *file);
  634. @end example
  635.  
  636. @subheading Description
  637.  
  638. This function (actually a macro) can be used to indicate if the given
  639. @var{file} is at the end-of-file or not. 
  640.  
  641. @subheading Return Value
  642.  
  643. Nonzero at end-of-file, zero otherwise.
  644.  
  645. @subheading Example
  646.  
  647. @example
  648. while (!feof(stdin))
  649.   gets(line);
  650. @end example
  651.  
  652. @c ----------------------------------------------------------------------
  653. @node ferror, fflush, feof, Alphabetical List
  654.  
  655. @heading @code{ferror}
  656. @subheading Syntax
  657.  
  658. @example
  659. #include <stdio.h>
  660.  
  661. int ferror(FILE *file);
  662. @end example
  663.  
  664. @subheading Description
  665.  
  666. This function (actually a macro) can be used to indicate if the given
  667. @var{file} has encountered an error or not.  @xref{clearerr}
  668.  
  669. @subheading Return Value
  670.  
  671. Nonzero for an error, zero otherwize.
  672.  
  673. @subheading Example
  674.  
  675. @example
  676. if (ferror(stdin))
  677.   exit(1);
  678. @end example
  679.  
  680. @c ----------------------------------------------------------------------
  681. @node fflush, ffs, ferror, Alphabetical List
  682.  
  683. @heading @code{fflush}
  684. @subheading Syntax
  685.  
  686. @example
  687. #include <stdio.h>
  688.  
  689. int fflush(FILE *file);
  690. @end example
  691.  
  692. @subheading Description
  693.  
  694. This function causes any unwritten buffered data to be written out to
  695. the given @var{file}.  This is useful in cases where the output is line
  696. buffered and you want to write a partial line. 
  697.  
  698. @subheading Return Value
  699.  
  700. Zero on success, -1 on error.
  701.  
  702. @subheading Example
  703.  
  704. @example
  705. printf("Enter value : ");
  706. fflush(stdout);
  707. scanf(result);
  708. @end example
  709.  
  710. @c ----------------------------------------------------------------------
  711. @node ffs, fgetc, fflush, Alphabetical List
  712.  
  713. @heading @code{ffs}
  714. @subheading Syntax
  715.  
  716. @example
  717. #include <string.h>
  718. int ffs(int mask);
  719. @end example
  720.  
  721. @subheading Description
  722.  
  723. This function returns the position of the least significant bit set in
  724. @var{mask}.  For example:
  725.  
  726. @example
  727. ffs(0x00000000) == 0
  728. ffs(0x00000001) == 1
  729. ffs(0x00000002) == 2
  730. ffs(0x00000004) == 3
  731. ffs(0x00010000) == 17
  732. ffs(0x00010010) == 5
  733. @end example
  734.  
  735. @subheading Return Value
  736.  
  737. The position of the bit, or zero if none are set.
  738.  
  739. @c ----------------------------------------------------------------------
  740. @node fgetc, fgetgrent, ffs, Alphabetical List
  741.  
  742. @heading @code{fgetc}
  743. @subheading Syntax
  744.  
  745. @example
  746. #include <stdio.h>
  747.  
  748. int fgetc(FILE *file);
  749. @end example
  750.  
  751. @subheading Description
  752.  
  753. Returns the next character in the given @var{file} as an unsigned char. 
  754.  
  755. @subheading Return Value
  756.  
  757. The given char (value 0..255) or @code{EOF} at end-of-file.
  758.  
  759. @subheading Example
  760.  
  761. @example
  762. int c;
  763. while((c=fgetc(stdin)) != EOF)
  764.   fputc(c, stdout);
  765. @end example
  766.  
  767. @c ----------------------------------------------------------------------
  768. @node fgetgrent, fgetpos, fgetc, Alphabetical List
  769.  
  770. @heading @code{fgetgrent}
  771. @subheading Syntax
  772.  
  773. @example
  774. #include <grp.h>
  775.  
  776. struct group *fgetgrent(FILE *file);
  777. @end example
  778.  
  779. @subheading Description
  780.  
  781. This function, in MS-DOS, is exactly the same as getgrent
  782. (@xref{getgrent}). 
  783.  
  784. @c ----------------------------------------------------------------------
  785. @node fgetpos, fgetpwent, fgetgrent, Alphabetical List
  786.  
  787. @heading @code{fgetpos}
  788. @subheading Syntax
  789.  
  790. @example
  791. #include <stdio.h>
  792.  
  793. int fgetpos(FILE *file, fpos_t *offset);
  794. @end example
  795.  
  796. @subheading Description
  797.  
  798. This function records the current file pointer for @var{file}, for
  799. later use by @code{fsetpos}.
  800.  
  801. @xref{fsetpos}.
  802.  
  803. @xref{ftell}.
  804.  
  805. @subheading Return Value
  806.  
  807. Zero if successful, nonzero if not.
  808.  
  809. @c ----------------------------------------------------------------------
  810. @node fgetpwent, fgets, fgetpos, Alphabetical List
  811.  
  812. @heading @code{fgetpwent}
  813. @subheading Syntax
  814.  
  815. @example
  816. #include <pwd.h>
  817.  
  818. struct passwd *fgetpwent(FILE *file);
  819. @end example
  820.  
  821. @subheading Description
  822.  
  823. This function, in MS-DOS, is exactly like @code{getpwent}
  824. (@xref{getpwent}). 
  825.  
  826. @c ----------------------------------------------------------------------
  827. @node fgets, _filbuf, fgetpwent, Alphabetical List
  828.  
  829. @heading @code{fgets}
  830. @subheading Syntax
  831.  
  832. @example
  833. #include <stdio.h>
  834.  
  835. char *fgets(char *buffer, int maxlength, FILE *file);
  836. @end example
  837.  
  838. @subheading Description
  839.  
  840. This function reads as much of a line from a file as possible, stopping
  841. when the buffer is full (@var{maxlength}-1 characters), an end-of-line
  842. is detected, or @code{EOF} or an error is detected.  It then stores a
  843. @code{NULL} to terminate the string.
  844.  
  845. @subheading Return Value
  846.  
  847. The address of the buffer is returned on success, if @code{EOF} is
  848. encountered before any characters are stored, or if an error is
  849. detected, @code{NULL} is returned instead. 
  850.  
  851. @subheading Example
  852.  
  853. @example
  854. char buf[100];
  855. while (fgets(buf, 100, stdin))
  856.   fputs(buf, stdout);
  857. @end example
  858.  
  859. @c ----------------------------------------------------------------------
  860. @node _filbuf, fileno, fgets, Alphabetical List
  861.  
  862. @heading @code{_filbuf}
  863.  
  864. @subheading Description
  865.  
  866. This is an internal function used to implement stream buffering.
  867.  
  868. @c ----------------------------------------------------------------------
  869. @node fileno, _findenv, _filbuf, Alphabetical List
  870.  
  871. @heading @code{fileno}
  872. @subheading Syntax
  873.  
  874. @example
  875. #include <stdio.h>
  876.  
  877. int fileno(FILE *file);
  878. @end example
  879.  
  880. @subheading Description
  881.  
  882. This function returns the raw file descriptor number that @var{file}
  883. uses for I/O. 
  884.  
  885. @subheading Return Value
  886.  
  887. The file descriptor number.
  888.  
  889. @c ----------------------------------------------------------------------
  890. @node _findenv, findfirst, fileno, Alphabetical List
  891.  
  892. @heading @code{_findenv}
  893.  
  894. @subheading Description
  895.  
  896. This is an internal function used by @code{getenv} and @code{setenv}. 
  897. @xref{getenv} @xref{setenv}
  898.  
  899. @c ----------------------------------------------------------------------
  900. @node findfirst, _findiop, _findenv, Alphabetical List
  901.  
  902. @heading @code{findfirst}
  903. @subheading Syntax
  904.  
  905. @example
  906. #include <dir.h>
  907.  
  908. int findfirst(const char *pathname, struct ffblk *ffblk, int attrib);
  909. @end example
  910.  
  911. @subheading Description
  912.  
  913. This function and the related @code{findnext} are used to scan
  914. directories for the list of files therein.  The @var{pathname} is a
  915. wildcard that specifies the directory and files to search for (such as
  916. @code{subdir/*.c}), @var{ffblk} is a structure to hold the results and
  917. state of the search, and @var{attrib} is a combination of the following:
  918.  
  919. @table @code
  920.  
  921. @item FA_RDONLY
  922.  
  923. Include read-only files in the search
  924.  
  925. @item FA_HIDDEN
  926.  
  927. Include hidden files in the search
  928.  
  929. @item FA_SYSTEM
  930.  
  931. Include system files in the search
  932.  
  933. @item FA_LABEL
  934.  
  935. Include the volume label in the search
  936.  
  937. @item FA_DIREC
  938.  
  939. Include subdirectories in the search
  940.  
  941. @item FA_ARCH
  942.  
  943. Include modified files in the search
  944.  
  945. @end table
  946.  
  947. Any file that doesn't have any flag bits that aren't specified is
  948. selected for the search.  Thus, if you specified @code{FA_DIREC} and
  949. @code{FA_LABEL}, you would get all subdirectories, the volume label, and
  950. any file that is neither read-only or modified. 
  951.  
  952. The results of the search are stored in @var{ffblk}:
  953.  
  954. @example
  955. struct ffblk @{
  956.   char ff_reserved[21];  /* used to hold the state of the search */
  957.   char ff_attrib;        /* actual attributes of the file found */
  958.   short ff_ftime;        /* hours:5, minutes:6, (seconds/2):5 */
  959.   short ff_fdate;        /* (year-1980):7, month:4, day:5 */
  960.   short ff_filler;       /* gcc aligns "long" different than DOS */
  961.   long ff_fsize;         /* size of file */
  962.   char ff_name[16];      /* name of file as ASCIIZ string */
  963. @}
  964. @end example
  965.  
  966. @subheading Return Value
  967.  
  968. Zero if a match is found, nonzero if none found.
  969.  
  970. @subheading Example
  971.  
  972. @example
  973. struct ffblk f;
  974. int done = findfirst("*.exe", &f, FA_ARCH|FA_RDONLY);
  975. while (!done)
  976. @{
  977.   printf("%10u %2d:%02d:%02d %2d/%02d/%4d %s\n",
  978.     f.ff_fsize,
  979.     (f.ff_ftime >> 11) & 0x1f,
  980.     (f.ff_ftime >>  5) & 0x3f,
  981.     (f.ff_ftime & 0x1f) * 2,
  982.     (f.ff_fdate >>  5) & 0x0f,
  983.     (f.ff_fdate & 0x1f),
  984.     ((f.ff_fdate >> 9) & 0x7f) + 1980,
  985.     f.ff_name);
  986.   done = findnext(&f);
  987. @}
  988. @end example
  989.  
  990. @c ----------------------------------------------------------------------
  991. @node _findiop, findnext, findfirst, Alphabetical List
  992.  
  993. @heading @code{_findiop}
  994.  
  995. @subheading Description
  996.  
  997. This is an internal function used by @code{fopen}. @xref{fopen}
  998.  
  999. @c ----------------------------------------------------------------------
  1000. @node findnext, _fixpath, _findiop, Alphabetical List
  1001.  
  1002. @heading @code{findnext}
  1003. @subheading Syntax
  1004.  
  1005. @example
  1006. #include <dir.h>
  1007.  
  1008. int findnext(struct ffblk *ffblk);
  1009. @end example
  1010.  
  1011. @subheading Description
  1012.  
  1013. This finds the next file in the search started by @code{findfirst}. @xref{findfirst}
  1014.  
  1015. @subheading Return Value
  1016.  
  1017. Zero if there was a match, else nonzero.
  1018.  
  1019. @c ----------------------------------------------------------------------
  1020. @node _fixpath, _flsbuf, findnext, Alphabetical List
  1021.  
  1022. @heading @code{_fixpath}
  1023. @subheading Syntax
  1024.  
  1025. @example
  1026. void _fixpath(const char *in_path, char *out_path);
  1027. @end example
  1028.  
  1029. @subheading Description
  1030.  
  1031. This function canonacalizes the input path @var{in_path} and stores the
  1032. result in the buffer pointed to by @var{out_path}.
  1033.  
  1034. The path is fixed by removing consecutive and trailing slashes, making
  1035. the path absolute if it's relative, removing "." components, collapsing
  1036. ".." components, adding a drive specifier if needed, and converting all
  1037. slashes to '/'. 
  1038.  
  1039. @subheading Return Value
  1040.  
  1041. None.
  1042.  
  1043. @subheading Example
  1044.  
  1045. @example
  1046. char oldpath[100], newpath[100];
  1047. scanf(oldpath);
  1048. _fixpath(oldpath, newpath);
  1049. printf("that really is %s\n", newpath);
  1050. @end example
  1051.  
  1052. @c ----------------------------------------------------------------------
  1053. @node _flsbuf, _fmode, _fixpath, Alphabetical List
  1054.  
  1055. @heading @code{_flsbuf}
  1056.  
  1057. @subheading Description
  1058.  
  1059. This is an internal function used to implement stream buffering.
  1060.  
  1061. @c ----------------------------------------------------------------------
  1062. @node _fmode, fnmatch, _flsbuf, Alphabetical List
  1063.  
  1064. @heading @code{_fmode}
  1065. @subheading Syntax
  1066.  
  1067. @example
  1068. #include <fcntl.h>
  1069.  
  1070. extern int _fmode;
  1071. @end example
  1072.  
  1073. @subheading Description
  1074.  
  1075. This variable may be set to @code{O_TEXT} or @code{O_BINARY} to specify
  1076. the mode that newly opened files should be opened in if the open call
  1077. did not specify.  @xref{open} @xref{fopen}
  1078.  
  1079. The default value is @code{O_TEXT}.
  1080.  
  1081. @subheading Example
  1082.  
  1083. @example
  1084. _fmode = O_BINARY;
  1085. @end example
  1086.  
  1087. @c ----------------------------------------------------------------------
  1088. @node fnmatch, fnmerge, _fmode, Alphabetical List
  1089.  
  1090. @heading @code{fnmatch}
  1091. @subheading Syntax
  1092.  
  1093. @example
  1094. #include <unistd.h>
  1095.  
  1096. int fnmatch(const char *pattern, const char *string, int flags);
  1097. @end example
  1098.  
  1099. @subheading Description
  1100.  
  1101. This function indicates if @var{string} matches the @var{pattern}.  The
  1102. pattern may include the following special characters:
  1103.  
  1104. @table @code
  1105.  
  1106. @item *
  1107.  
  1108. Matches zero of more characters.
  1109.  
  1110. @item ?
  1111.  
  1112. Matches exactly one character
  1113.  
  1114. @item [...]
  1115.  
  1116. Matches one character if it's in a range of characters.  If the first
  1117. character is @code{!}, matches if the character is not in the range. 
  1118. Between the brackets, the range is specified by listing the characters
  1119. that are in the range, or two characters separated by @code{-} to
  1120. indicate all characters in that range.  For example, @code{[a-d]}
  1121. matches @code{a}, @code{b}, @code{c}, or @code{d}. 
  1122.  
  1123. @item \
  1124.  
  1125. Causes the next character to not be treated as a wildcard.  For example,
  1126. @code{\*} matches an asterisk.  This is only available if @var{flags}
  1127. includes @code{FNM_QUOTE}. 
  1128.  
  1129. @end table
  1130.  
  1131. The value of @var{flags} is a combination of zero of more of the
  1132. following:
  1133.  
  1134. @table @code
  1135.  
  1136. @item FNM_PATHNAME
  1137.  
  1138. This means that the string should be treated as a pathname, in that the
  1139. slash character @code{/} never matches any of the wildcards. 
  1140.  
  1141. @item FNM_QUOTE
  1142.  
  1143. This means that the backslash @code{\\} may be used for quoting special
  1144. characters in the pattern. 
  1145.  
  1146. @end table
  1147.  
  1148. @subheading Return Value
  1149.  
  1150. Zero if the string does not match, nonzero if it does.
  1151.  
  1152. @subheading Example
  1153.  
  1154. @example
  1155. if (fnmatch("*.[ch]", filename, FNM_PATH|FNM_QUOTE))
  1156.   do_source_file(filename);
  1157. @end example
  1158.  
  1159. @c ----------------------------------------------------------------------
  1160. @node fnmerge, fnsplit, fnmatch, Alphabetical List
  1161.  
  1162. @heading @code{fnmerge}
  1163. @subheading Syntax
  1164.  
  1165. @example
  1166. #include <dir.h>
  1167.  
  1168. void fnmerge (char *path, const char *drive, const char *dir,
  1169.         const char *name, const char *ext);
  1170. @end example
  1171.  
  1172. @subheading Description
  1173.  
  1174. This function constructs a file @var{path} from its components.
  1175.  
  1176. @xref{fnsplit}
  1177.  
  1178. @subheading Return Value
  1179.  
  1180. None.
  1181.  
  1182. @subheading Example
  1183.  
  1184. @example
  1185. char buf[MAXPATH];
  1186. fnmerge(buf, "d:", "/foo/", "data", ".txt");
  1187. @end example
  1188.  
  1189. @c ----------------------------------------------------------------------
  1190. @node fnsplit, fopen, fnmerge, Alphabetical List
  1191.  
  1192. @heading @code{fnsplit}
  1193. @subheading Syntax
  1194.  
  1195. @example
  1196. #include <dir.h>
  1197.  
  1198. int fnsplit (const char *path, char *drive, char *dir, 
  1199.         char *name, char *ext);
  1200. @end example
  1201.  
  1202. @subheading Description
  1203.  
  1204. This function decomposes a @var{path} into its components.
  1205.  
  1206. @xref{fnmerge}
  1207.  
  1208. @subheading Return Value
  1209.  
  1210. A flag that indicates which components were found:
  1211.  
  1212. @table @code
  1213.  
  1214. @item DRIVE
  1215.  
  1216. The drive letter was found.
  1217.  
  1218. @item DIRECTORY
  1219.  
  1220. A directory or subdirectories was found.
  1221.  
  1222. @item FILENAME
  1223.  
  1224. A filename was found.
  1225.  
  1226. @item EXTENSION
  1227.  
  1228. An extension was found.
  1229.  
  1230. @item WILDCARDS
  1231.  
  1232. The path included @code{*} or @code{?}.
  1233.  
  1234. @end table
  1235.  
  1236. @subheading Example
  1237.  
  1238. @example
  1239. char d[MAXDRIVE], p[MAXDIR], f[MAXFILE], e[MAXEXT];
  1240. int which = fnsplit("d:/djgpp/bin/gcc.exe", d, p, f, e);
  1241. d = "d:"
  1242. p = "/djgpp/bin/"
  1243. f = "gcc"
  1244. e = ".exe"
  1245. @end example
  1246.  
  1247. @c ----------------------------------------------------------------------
  1248. @node fopen, fork, fnsplit, Alphabetical List
  1249.  
  1250. @heading @code{fopen}
  1251. @subheading Syntax
  1252.  
  1253. @example
  1254. #include <stdio.h>
  1255. FILE *fopen(const char *filename, const char *mode);
  1256. @end example
  1257.  
  1258. @subheading Description
  1259.  
  1260. This function opens a stream corresponding to the named @var{filename}
  1261. with the given @var{mode}.  The mode can be one of the following:
  1262.  
  1263. @table @code
  1264.  
  1265. @item r
  1266.  
  1267. Open an existing file for reading.
  1268.  
  1269. @item w
  1270.  
  1271. Create a new file (or truncate an existing file) and open it for
  1272. writing. 
  1273.  
  1274. @item a
  1275.  
  1276. Open an existing file (or create a new one) for writing.  The file
  1277. pointer is positioned to the end of the file before every write. 
  1278.  
  1279. @end table
  1280.  
  1281. Followed by any of these characters:
  1282.  
  1283. @table @code
  1284.  
  1285. @item b
  1286.  
  1287. Force the file to be open in binary mode instead of the default mode.
  1288.  
  1289. @item t
  1290.  
  1291. Force the file to be open in text mode instead of the default mode.
  1292.  
  1293. @item +
  1294.  
  1295. Open the file as with @code{O_RDWR} so that both reads and writes
  1296. can be done to the same file.
  1297.  
  1298. @end table
  1299.  
  1300. If the file is open for both reading and writing, you must call
  1301. @code{fflush}, @code{fseek}, or @code{rewind} before switching from read
  1302. to write or from write to read. 
  1303.  
  1304. The open file is set to line buffered if the underlying object is a
  1305. device (stdin, stdout, etc), or is fully buffered if the underlying
  1306. object is a disk file (data.c, etc).
  1307.  
  1308. If @code{b} or @code{t} is not specified in @var{mode}, the file type is
  1309. chosen by the value of @code{fmode} (@xref{_fmode}). 
  1310.  
  1311. @subheading Return Value
  1312.  
  1313. A pointer to the @code{FILE} object, or @code{NULL} if there was an
  1314. error. 
  1315.  
  1316. @subheading Example
  1317.  
  1318. @example
  1319. FILE *f = fopen("foo", "rb+"); /* open existing file for read/write, binary mode */
  1320. @end example
  1321.  
  1322. @c ----------------------------------------------------------------------
  1323. @node fork, fpathconf, fopen, Alphabetical List
  1324.  
  1325. @heading @code{fork}
  1326.  
  1327. @subheading Description
  1328.  
  1329. This function always returns -1, as MS-DOS does not support multiple
  1330. processes.  It exists only to assist in porting Unix programs. 
  1331.  
  1332. @c ----------------------------------------------------------------------
  1333. @node fpathconf, fprintf, fork, Alphabetical List
  1334.  
  1335. @heading @code{fpathconf}
  1336. @subheading Syntax
  1337.  
  1338. @example
  1339. #include <unistd.h>
  1340.  
  1341. long fpathconf(int fd, int name);
  1342. @end example
  1343.  
  1344. @subheading Description
  1345.  
  1346. Returns configuration information on the filesystem that the
  1347. open file resides on.  @xref{pathconf}
  1348.  
  1349. @subheading Return Value
  1350.  
  1351. The configuration value.
  1352.  
  1353. @c ----------------------------------------------------------------------
  1354. @node fprintf, fpurge, fpathconf, Alphabetical List
  1355.  
  1356. @heading @code{fprintf}
  1357. @subheading Syntax
  1358.  
  1359. @example
  1360. #include <stdio.h>
  1361.  
  1362. int fprintf(FILE *file, const char *format, @dots{});
  1363. @end example
  1364.  
  1365. @subheading Description
  1366.  
  1367. Prints formatted output to the named file.  @xref{printf}
  1368.  
  1369. @subheading Return Value
  1370.  
  1371. The number of characters written.
  1372.  
  1373. @c ----------------------------------------------------------------------
  1374. @node fpurge, fputc, fprintf, Alphabetical List
  1375.  
  1376. @heading @code{fpurge}
  1377. @subheading Syntax
  1378.  
  1379. @example
  1380. #include <stdio.h>
  1381.  
  1382. int fpurge(FILE *file);
  1383. @end example
  1384.  
  1385. @subheading Description
  1386.  
  1387. This function purges the buffer for @var{file} without writing it to
  1388. disk. 
  1389.  
  1390. @subheading Return Value
  1391.  
  1392. Zero on success, -1 on failure.
  1393.  
  1394. @c ----------------------------------------------------------------------
  1395. @node fputc, fputs, fpurge, Alphabetical List
  1396.  
  1397. @heading @code{fputc}
  1398. @subheading Syntax
  1399.  
  1400. @example
  1401. #include <stdio.h>
  1402.  
  1403. int fputc(int character, FILE *file);
  1404. @end example
  1405.  
  1406. @subheading Description
  1407.  
  1408. This function writes the given @var{character} to the given @code{file}.
  1409.  
  1410. @subheading Return Value
  1411.  
  1412. The given character [0..255] or @code{EOF}.
  1413.  
  1414. @subheading Example
  1415.  
  1416. @example
  1417. fputc('\n', stdout);
  1418. @end example
  1419.  
  1420. @c ----------------------------------------------------------------------
  1421. @node fputs, fread, fputc, Alphabetical List
  1422.  
  1423. @heading @code{fputs}
  1424. @subheading Syntax
  1425.  
  1426. @example
  1427. #include <stdio.h>
  1428.  
  1429. int fputs(const char *string, FILE *file);
  1430. @end example
  1431.  
  1432. @subheading Description
  1433.  
  1434. This function all the characters of @var{string} (except the trailing
  1435. @code{NULL}) to the given @var{file}.
  1436.  
  1437. @subheading Return Value
  1438.  
  1439. A nonnegative number on success, @code{EOF} on error.
  1440.  
  1441. @subheading Example
  1442.  
  1443. @example
  1444. fputs("Hello\n", stdout);
  1445. @end example
  1446.  
  1447. @c ----------------------------------------------------------------------
  1448. @node fread, free, fputs, Alphabetical List
  1449.  
  1450. @heading @code{fread}
  1451. @subheading Syntax
  1452.  
  1453. @example
  1454. #include <stdio.h>
  1455.  
  1456. size_t fread(void *buffer, size_t size, size_t number, FILE *file);
  1457. @end example
  1458.  
  1459. @subheading Description
  1460.  
  1461. This function reads @var{size}*@var{number} characters from @var{file}
  1462. to @var{buffer}. 
  1463.  
  1464. @subheading Return Value
  1465.  
  1466. The number of items of size @var{size} read, or -1 on error.
  1467.  
  1468. @subheading Example
  1469.  
  1470. @example
  1471. int foo[10];
  1472. fread(foo, sizeof(int), 10, stdin);
  1473. @end example
  1474.  
  1475. @c ----------------------------------------------------------------------
  1476. @node free, freopen, fread, Alphabetical List
  1477.  
  1478. @heading @code{free}
  1479. @subheading Syntax
  1480.  
  1481. @example
  1482. #include <stdio.h>
  1483.  
  1484. void free(void *ptr);
  1485. @end example
  1486.  
  1487. @subheading Description
  1488.  
  1489. Returns the allocated memory to the heap (@xref{malloc}).  If the
  1490. @var{ptr} is @code{NULL}, it does nothing. 
  1491.  
  1492. @subheading Return Value
  1493.  
  1494. None.
  1495.  
  1496. @subheading Example
  1497.  
  1498. @example
  1499. char *q = (char *)malloc(20);
  1500. free(q);
  1501. @end example
  1502.  
  1503. @c ----------------------------------------------------------------------
  1504. @node freopen, fscanf, free, Alphabetical List
  1505.  
  1506. @heading @code{freopen}
  1507. @subheading Syntax
  1508.  
  1509. @example
  1510. #include <stdio.h>
  1511.  
  1512. FILE *freopen(const char *filename, const char *mode, FILE *file);
  1513. @end example
  1514.  
  1515. @subheading Description
  1516.  
  1517. This function closes @var{file} if it was open, then opens a new
  1518. file like @code{fopen(filename, mode)} but it reuses @var{file}.
  1519.  
  1520. This is useful to, for example, associate @code{stdout} with a new file. 
  1521.  
  1522. @subheading Return Value
  1523.  
  1524. The new file, or @code{NULL} on error. 
  1525.  
  1526. @subheading Example
  1527.  
  1528. @example
  1529. freopen("/tmp/stdout.dat", "wb", stdout);
  1530. @end example
  1531.  
  1532. @c ----------------------------------------------------------------------
  1533. @node fscanf, fseek, freopen, Alphabetical List
  1534.  
  1535. @heading @code{fscanf}
  1536. @subheading Syntax
  1537.  
  1538. @example
  1539. #include <stdio.h>
  1540.  
  1541. int fscanf(FILE *file, const char *format, @dots{});
  1542. @end example
  1543.  
  1544. @subheading Description
  1545.  
  1546. This function scans formatted text from @var{file} and stores it in the
  1547. variables pointed to by the arguments.  @xref{scanf}
  1548.  
  1549. @subheading Return Value
  1550.  
  1551. The number of items successfully scanned.
  1552.  
  1553. @c ----------------------------------------------------------------------
  1554. @node fseek, fsetpos, fscanf, Alphabetical List
  1555.  
  1556. @heading @code{fseek}
  1557. @subheading Syntax
  1558.  
  1559. @example
  1560. #include <stdio.h>
  1561.  
  1562. int fseek(FILE *file, long offset, int mode);
  1563. @end example
  1564.  
  1565. @subheading Description
  1566.  
  1567. This function moves the file pointer for @var{file} according to
  1568. @var{mode}:
  1569.  
  1570. @table @code
  1571.  
  1572. @item SEEK_SET
  1573.  
  1574. The file pointer is moved to the offset specified.
  1575.  
  1576. @item SEEK_CUR
  1577.  
  1578. The file pointer is moved relative to its current position.
  1579.  
  1580. @item SEEK_END
  1581.  
  1582. The file pointer is moved to a position @var{offset} bytes from the end
  1583. of the file.  The offset is usually nonpositive in this case. 
  1584.  
  1585. @end table
  1586.  
  1587. @emph{Warning!} The ANSI standard only allows values of zero for
  1588. @var{offset} when @var{whence} is not @code{SEEK_SET} and the file has
  1589. been opened as a text file.  Although this restriction is not enforced,
  1590. beware that there is not a one-to-one correspondence between file
  1591. characters and text characters under MS-DOS, so some @code{fseek}
  1592. operations may not do exactly what you expect. 
  1593.  
  1594. @subheading Return Value
  1595.  
  1596. Zero if successful, nonzero if not. 
  1597.  
  1598. @subheading Example
  1599.  
  1600. @example
  1601. fseek(stdin, 12, SEEK_CUR); /* skip 12 bytes */
  1602. @end example
  1603.  
  1604. @c ----------------------------------------------------------------------
  1605. @node fsetpos, fstat, fseek, Alphabetical List
  1606.  
  1607. @heading @code{fsetpos}
  1608. @subheading Syntax
  1609.  
  1610. @example
  1611. #include <stdio.h>
  1612.  
  1613. int fsetpos(FILE *file, const fpos_t *offset);
  1614. @end example
  1615.  
  1616. @subheading Description
  1617.  
  1618. This function moves the file pointer for @var{file} to position
  1619. @var{offset}, as recorded by @code{fgetpos}.
  1620.  
  1621. @xref{fgetpos}.
  1622.  
  1623. @xref{fseek}.
  1624.  
  1625. @subheading Return Value
  1626.  
  1627. Zero if successful, nonzero if not.
  1628.  
  1629. @c ----------------------------------------------------------------------
  1630. @node fstat, fsync, fsetpos, Alphabetical List
  1631.  
  1632. @heading @code{fstat}
  1633. @subheading Syntax
  1634.  
  1635. @example
  1636. #include <sys/stat.h>
  1637.  
  1638. int fstat(int file, struct stat *sbuf);
  1639. @end example
  1640.  
  1641. @subheading Description
  1642.  
  1643. This function obtains the status of the open file @var{file} and stores
  1644. it in @var{sbuf}.  @xref{stat}
  1645.  
  1646. @subheading Return Value
  1647.  
  1648. Zero on success, nonzero on failure. 
  1649.  
  1650. @c ----------------------------------------------------------------------
  1651. @node fsync, ftell, fstat, Alphabetical List
  1652.  
  1653. @heading @code{fsync}
  1654. @subheading Syntax
  1655.  
  1656. @example
  1657. #include <osfcn.h>
  1658.  
  1659. int fsync(int file);
  1660. @end example
  1661.  
  1662. @subheading Description
  1663.  
  1664. Forces all information about the file to be synchronized with the disk
  1665. image.
  1666.  
  1667. @subheading Return Value
  1668.  
  1669. Zero on success, nonzero on failure. 
  1670.  
  1671. @subheading Example
  1672.  
  1673. @example
  1674. fsync(fileno(stdout));
  1675. @end example
  1676.  
  1677. @c ----------------------------------------------------------------------
  1678. @node ftell, ftime, fsync, Alphabetical List
  1679.  
  1680. @heading @code{ftell}
  1681. @subheading Syntax
  1682.  
  1683. @example
  1684. #include <stdio.h>
  1685.  
  1686. long ftell(FILE *file);
  1687. @end example
  1688.  
  1689. @subheading Description
  1690.  
  1691. Returns the current file position for @code{file}.  This is suitable for
  1692. a future call to @code{fseek}. 
  1693.  
  1694. @subheading Return Value
  1695.  
  1696. The file position, or -1 on error. 
  1697.  
  1698. @subheading Example
  1699.  
  1700. @example
  1701. long p = ftell(stdout);
  1702. @end example
  1703.  
  1704. @c ----------------------------------------------------------------------
  1705. @node ftime, ftruncate, ftell, Alphabetical List
  1706.  
  1707. @heading @code{ftime}
  1708. @subheading Syntax
  1709.  
  1710. @example
  1711. #include <sys/timeb.h>
  1712.  
  1713. int ftime(struct timeb *buf);
  1714. @end example
  1715.  
  1716. @subheading Description
  1717.  
  1718. This function stores the current time in the structure @var{buf}.  The
  1719. format of @code{struct timeb} is:
  1720.  
  1721. @example
  1722. struct timeb @{
  1723.   time_t         time;     /* seconds since 00:00:00 GMT 1/1/1970 */
  1724.   unsigned short millitm;  /* milliseconds */
  1725.   short          timezone; /* difference between GMT and local, minutes */
  1726.   short          dstflag;  /* set if daylight savings time in affect */
  1727. @};
  1728. @end example
  1729.  
  1730. @subheading Return Value
  1731.  
  1732. Zero on success, nonzero on error.
  1733.  
  1734. @subheading Example
  1735.  
  1736. @example
  1737. struct timeb t;
  1738. ftime(&t);
  1739. @end example
  1740.  
  1741. @c ----------------------------------------------------------------------
  1742. @node ftruncate, _fwalk, ftime, Alphabetical List
  1743.  
  1744. @heading @code{ftruncate}
  1745. @subheading Syntax
  1746.  
  1747. @example
  1748. #include <osfcn.h>
  1749.  
  1750. int ftruncate(int file, unsigned long where);
  1751. @end example
  1752.  
  1753. @subheading Description
  1754.  
  1755. This function truncates @var{file} at @var{where} length.  This only
  1756. works if the file is closed right after this call. 
  1757.  
  1758. @subheading Return Value
  1759.  
  1760. Zero for success, nonzero for failure.
  1761.  
  1762. @subheading Example
  1763.  
  1764. @example
  1765. int x = open("data", O_WRONLY);
  1766. ftruncate(x, 1000);
  1767. close(x);
  1768. @end example
  1769.  
  1770. @c ----------------------------------------------------------------------
  1771. @node _fwalk, fwrite, ftruncate, Alphabetical List
  1772.  
  1773. @heading @code{_fwalk}
  1774. @subheading Syntax
  1775.  
  1776. @example
  1777. void _fwalk(void (*function)(FILE *file));
  1778. @end example
  1779.  
  1780. @subheading Description
  1781.  
  1782. For each open file in the system, the given @var{function} is called,
  1783. passing the file pointer as it's only argument
  1784.  
  1785. @subheading Return Value
  1786.  
  1787. None.
  1788.  
  1789. @subheading Example
  1790.  
  1791. @example
  1792. void pfile(FILE *x)
  1793. @{ printf("FILE at %x\n", x); @}
  1794.  
  1795. _fwalk(pfile);
  1796. @end example
  1797.  
  1798. @c ----------------------------------------------------------------------
  1799. @node fwrite, _get_default_drive, _fwalk, Alphabetical List
  1800.  
  1801. @heading @code{fwrite}
  1802. @subheading Syntax
  1803.  
  1804. @example
  1805. #include <stdio.h>
  1806.  
  1807. size_t fwrite(void *buffer, size_t size, size_t number, FILE *file);
  1808. @end example
  1809.  
  1810. @subheading Description
  1811.  
  1812. This function writes @var{size}*@var{number} characters from @var{buffer}
  1813. to @var{file}.
  1814.  
  1815. @subheading Return Value
  1816.  
  1817. The number of items of size @var{size} written, or -1 on error.
  1818.  
  1819. @subheading Example
  1820.  
  1821. @example
  1822. int foo[10];
  1823. fwrite(foo, sizeof(int), 10, stdin);
  1824. @end example
  1825.  
  1826.  
  1827.